package game;

import sengine.Character;
import sengine.Sprite;
import sengine.Texture;

/**
 * A simple gun for testing and other such purposes
 *
 * @author twoodf5611
 */
public class SimpleGun extends Sprite implements Equipment {
    private byte direction = 0;

    public SimpleGun() {
        super(0, 0, 50, 10);
        setPhysType(Sprite.PhysicsType.FLOATING);
        setTexture(Texture.loadTexture("gun-blob.png"));
    }

    @Override
    public void click(float distance, float angle) {
        System.out.println("CLICK " + distance + ", " + Math.toDegrees(angle));
        int x = (int) (90-angle > 0 ? getX() + getWidth() + 5 : getX() - 5);
        int y = (int) (getY() + 5);
        //int y = (int) getY();
        SimpleBullet bullet = new SimpleBullet(x, y, angle);
//        setR((float) -(angle * 180 / Math.PI));
        addSprite(bullet);
    }

    @Override
    public void playerLocUpdate(float x, float y, float r, byte direction) {
        setX(x + 10);
        setY(y + 30);
        this.direction = direction;
    }

    protected class SimpleBullet extends Bullet {

        public static final int BULLET_VEL = 500;

        public SimpleBullet(int x, int y, float r) {
            super(x, y, 5, 5);
            if(direction>=0){
                setVx(BULLET_VEL);
            } else {
                setVx(-BULLET_VEL);
            }
        }
        
        @Override
        public void collideTarget(Character target) {
            if(!(target instanceof sengine.PlayerCharacter)) {
                super.collideTarget(target);
            }
        }
        
        @Override
        public int getDamage() {
            return 10;
        }
    }
}
